<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px" class="queryForms">
			<el-form-item label="产品名称" prop="productName">
				<el-input maxlength="20" show-word-limit v-model="queryParams.productName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="产品型号" prop="productModel">
				<el-input maxlength="20" show-word-limit v-model="queryParams.productModel" placeholder="请输入产品型号" clearable @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row class="mb8">
			<el-col :span="1.5">
				<el-button type="primary" :disabled="multiple" size="mini" @click="handleEditWork" v-hasPermi="['erp:productTechnologyVersions:editwork']">批量设置工分</el-button>
			</el-col>
			<right-toolbar @changeTableData="changeTableData" menuNames="productTechnology30" :showSearch.sync="showSearch" @queryTable="getList" :columns.sync="columns" perm="erp:productTechnology:list"></right-toolbar>
		</el-row>

		<div :class="sidebar.opened && eleTabTop <= 85 ? 'eleTab' : !sidebar.opened && eleTabTop <= 85 ? 'eleTabs' : ''" class="informationTab" ref="eleTab">
			<el-table ref="table" @row-click="row_click" v-loading="loading" :data="productData" border height="100%" @selection-change="handleSelectionChange">
				<el-table-column type="selection" width="55" align="center" />
				<el-table-column label="序号" align="center" type="index" width="55" />
				<el-table-column label="产品名称" prop="productName" min-width="150" :show-overflow-tooltip="true" v-if="columns[0].visible" />
				<el-table-column label="产品型号" prop="productModel" min-width="150" :show-overflow-tooltip="true" v-if="columns[1].visible" />
				<el-table-column label="工艺审批状态" align="center" prop="approvalStatus" min-width="150" :show-overflow-tooltip="true" v-if="columns[2].visible" />
				<el-table-column label="工艺版本" align="center" prop="productVersions" min-width="150" :show-overflow-tooltip="true" v-if="columns[3].visible" />
				<el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="120">
					<template slot-scope="scope">
						<el-button size="mini" type="text" icon="el-icon-s-operation" @click="handleUpdate(scope.row)" v-hasPermi="['erp:productTechnology:approve']">工艺流程</el-button>
					</template>
				</el-table-column>
			</el-table>
		</div>

		<pagination menuNames="Pagination35" v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

		<el-dialog title="计件工分" :visible.sync="openWork" width="900px" append-to-body v-dialogDrag>
			<el-table :data="workLists" border>
				<el-table-column label="序号" align="center" type="index" width="55" />
				<el-table-column label="计件工分名称" align="center" prop="workpointsName" />
				<el-table-column label="计件工分" align="center" prop="workpointsNumber">
					<template slot-scope="scope">
						<el-input-number v-model="scope.row.workpointsNumber" :precision="2" :step="0.1" :max="100000000"></el-input-number>
					</template>
				</el-table-column>
			</el-table>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitworkForm">确 定</el-button>
				<el-button @click="cancelworkForm">取 消</el-button>
			</div>
		</el-dialog>
	</div>
</template>
<script>
import { productList, batchEditWorkpoints } from "@/api/productTechnology/productTechnology"
import { mapGetters } from "vuex"
import searchStateMixin from "@/layout/mixin/searchStateMixin.js"
import DocumentShow from "@/views/components/DocumentShow"
import { getcolumn } from "@/api/selectList"
export default {
	name: "productTechnology_menu",
	components: { DocumentShow },
	mixins: [searchStateMixin],
	computed: {
		...mapGetters(["sidebar"])
	},
	data() {
		return {
			// 非多个禁用
			multiple: true,
			workLists: [
				{
					workpointsName: "质检",
					workpointsNumber: 0,
					workpointsSerialNumber: "11"
				},
				{
					workpointsName: "军检",
					workpointsNumber: 0,
					workpointsSerialNumber: "12"
				},
				{
					workpointsName: "成品外观检查",
					workpointsNumber: 0,
					workpointsSerialNumber: "13"
				},
				{
					workpointsName: "包装封箱",
					workpointsNumber: 0,
					workpointsSerialNumber: "14"
				},
				{
					workpointsName: "装车",
					workpointsNumber: 0,
					workpointsSerialNumber: "15"
				}
			],
			openWork: false,
			fileVedioList: [],
			showfileListDialog: false,
			showTodoListDialog: false,
			eleTabTop: 0, //表格容器距浏览器顶部距离
			queryParams: { pageNum: 1, pageSize: 10, productName: undefined, productModel: undefined, state: "1" },
			// 遮罩层
			loading: true,
			// 选中数组
			ids: [],
			// 非单个禁用
			single: true,
			// 显示搜索条件
			showSearch: true,
			// 总条数
			total: 0,
			// 列表格数据
			productData: [],
			// 列信息
			columns: [
				{ key: 0, label: `产品名称`, visible: true },
				{ key: 1, label: `产品型号`, visible: true },
				{ key: 2, label: `工艺审批状态`, visible: true },
				{ key: 3, label: `工艺版本`, visible: true }
			]
		}
	},
	// created() { this.getSize()},
	mounted() {
		// 滚动条的获取
		this.handleScrollx()
		window.addEventListener("scroll", this.handleScrollx, true)
	},
	watch: {
		"$route.query": {
			handler(newQuery, oldQuery) {
				if (newQuery.queryData) {
					if (Object.keys(newQuery.queryData).length === 0) {
						this.resetForm("queryForm")
						// this.getSize()
					} else {
						this.queryParams = { ...this.queryParams, ...JSON.parse(newQuery.queryData) }
						// this.getSize()
					}
				}
				this.getSize()
			},
			immediate: true, // 立即执行一次
			deep: true // 深度监听
		}
	},
	activated() {
		// this.getSize()
		//获取表格容器距页面头部的距离
		this.handleScrollx()
	},
	destroyed() {
		window.removeEventListener("scroll", this.handleScrollx, true)
	},
	methods: {
		getSize() {
			getcolumn({ pageName: "Pagination35" }).then(response => {
				this.queryParams.pageSize = response.data.length ? (response.data[0].limit ? response.data[0].limit : 10) : 10
				this.getList()
			})
		},
		setWorkForm() {
			this.workLists = [
				{
					workpointsName: "质检",
					workpointsNumber: 0,
					workpointsSerialNumber: "11"
				},
				{
					workpointsName: "军检",
					workpointsNumber: 0,
					workpointsSerialNumber: "12"
				},
				{
					workpointsName: "成品外观检查",
					workpointsNumber: 0,
					workpointsSerialNumber: "13"
				},
				{
					workpointsName: "包装封箱",
					workpointsNumber: 0,
					workpointsSerialNumber: "14"
				},
				{
					workpointsName: "装车",
					workpointsNumber: 0,
					workpointsSerialNumber: "15"
				}
			]
		},
		submitworkForm() {
			const loading = this.$loading({
				lock: true,
				text: "Loading",
				spinner: "el-icon-loading",
				background: "rgba(0, 0, 0, 0.7)"
			})
			batchEditWorkpoints({
				productIds: this.ids,
				workPoints: this.workLists
			})
				.then(res => {
					this.$modal.msgSuccess("设置成功")
					this.openWork = false
					localStorage.setItem("todoMessage", "productTechnology1")
					this.$refs.table.clearSelection()
					loading.close()
				})
				.catch(() => {
					loading.close()
				})
				.finally(() => {
					loading.close()
				})
		},
		cancelworkForm() {
			this.openWork = false
			this.setWorkForm()
		},
		handleEditWork() {
			this.setWorkForm()
			this.openWork = true
		},
		// 多选框选中数据
		handleSelectionChange(selection) {
			this.ids = selection.map(item => item.id)
			this.single = selection.length != 1
			this.multiple = !selection.length
		},
		// 单击表格行
		row_click(row, column, event) {
			if (column && column.label == "操作") {
				return
			} else {
				this.$refs.table.toggleRowSelection(row)
			}
		},
		changeTableData() {
			this.$nextTick(() => {
				this.$refs.table.doLayout()
			})
		},

		//获取表格容器距页面头部的距离
		handleScrollx() {
			this.eleTabTop = this.$refs.eleTab.getBoundingClientRect().top
		},
		/** 查询产品列列表 */
		getList() {
			this.loading = true
			productList(this.queryParams).then(response => {
				this.productData = response.rows
				this.total = response.total
				this.loading = false
			})
		},
		// 表单重置
		reset() {
			this.form = {
				id: null,
				productTypeId: null,
				productName: null,
				productModel: null
			}
			this.resetForm("form")
		},
		/** 搜索按钮操作 */
		handleQuery() {
			this.queryParams.pageNum = 1
			this.saveSearchState()
			this.getList()
		},
		/** 重置按钮操作 */
		resetQuery() {
			this.resetForm("queryForm")
			this.queryParams.productName = undefined
			this.queryParams.productModel = undefined
			this.clearSearchCache()
			this.handleQuery()
		},
		handleUpdate(row) {
			localStorage.setItem("productId", row.id)
			this.$router.push({
				path: "/productTechnology/Technology/productTechnologyVersions/index",
				query: {
					id: row.id,
					productName: row.productName,
					productModel: row.productModel
				}
			})
		}
	}
}
</script>
<style lang="scss" scoped>
//  table{
//   colgroup{
//     col{
//       min-width: 100px !important;
//     }
//   }
// }
// table,tbody,thead {
//   width: 100% !important;
// }
// ::v-deep colgroup {
//   position: absolute;
//   width: 100% !important;
//   display: flex;
// }
// ::v-deep col {
//   flex: 1;
//   text-align: center;
// }
::v-deep .el-table__fixed-header-wrapper .fixed-width {
	width: 122px !important;
}
</style>
